<?php
// +----------------------------------------------------------------------
// | MyCentOS
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.mycentos.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 琥珀 <317559272@qqq.com><http://www.mycentos.com>
// +----------------------------------------------------------------------
// | @date  : 2015-04-09 11:02:56
// +----------------------------------------------------------------------
// | @Last Modified by:  琥珀
// +----------------------------------------------------------------------
// | @Last Modified time: 2015-04-09 15:58:33
// +-----------------------------------------------------------------------

/**
 * 后台公共控制器
 */
namespace Admin\Controller;
use Think\Controller;
class PublicController extends Controller {
    //首页
    public function index(){
        if (is_login()) {
            $this->redirect('Index/index');
        }else{
           $this->redirect('login');
        }
    }
    //登陆
    public function login($username = null, $password = null, $verify = null){
        if (IS_POST) {
            if(!check_verify($verify,$id='1')){
                $this->error('验证码错误');
            }
            $user = D('Login');
            $rs = $user->login($username, $password);
            switch ($rs) {
                case '1':
                    $this->success('登陆成功!',U('Index/index'));
                    break;
                case '2':
                    $this->error('用户不能为空!');
                    break;
                case '3':
                    $this->error('密码不能为空!');
                    break;
                case '4':
                    $this->error('用户名或者密码错误!');
                    break;
                default:
                    $this->error('未知错误!请联系管理员');
                    break;
            }
        }else{
            $this->display();
        }

    }
    //验证码
    public function verify(){
        $config = array(
            'fontSize'    =>    25,
            'length'      =>    2,
            'useNoise'    =>    true,
            );
        $Verify = new \Think\Verify($config);
        $Verify->entry(1);
    }
    //退出登陆
    public function logout(){
        if (is_login()) {
            session(null);
            $this->redirect('login');
        }else{
            $this->redirect('login');
        }
    }
}